/**
 * @filename:SysUsersRolesServiceImpl 2023-10-22 00:33:19
 * @project xxx系统  1.0
 * Copyright(c) 2021 fangdy Co. Ltd.
 * All right reserved.
 */
package org.fdy.bgadmin.service.impl;

import org.fdy.bgadmin.entity.SysUsersRoles;
import org.fdy.bgadmin.dao.SysUsersRolesDao;
import org.fdy.bgadmin.service.SysUsersRolesService;
import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.util.GraphicsRenderingHints;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;

/**
 * @Description:(sys_users_roles服务实现)
 *
 * @version: 1.0
 * @author: fangdy
 *
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SysUsersRolesServiceImpl  extends ServiceImpl<SysUsersRolesDao, SysUsersRoles> implements SysUsersRolesService  {


    public static void main(String[] args) throws IOException, PDFException, PDFSecurityException {

        String filePath = "C:\\Users\\fangd\\Desktop\\pdf\\药品黑匣子数据库备份文档.pdf";
        Document document = new Document();
        document.setFile(filePath);
        float scale = 2.5f;//缩放比例
        float rotation = 0f;//旋转角度

        for (int i = 0; i < document.getNumberOfPages(); i++) {
            BufferedImage image = (BufferedImage)
                    document.getPageImage(i, GraphicsRenderingHints.SCREEN, org.icepdf.core.pobjects.Page.BOUNDARY_CROPBOX, rotation, scale);
            RenderedImage rendImage = image;
            try {
                File file = new File("C:\\Users\\fangd\\Desktop\\pdf\\iii_" + i + ".png");
                ImageIO.write(rendImage, "png", file);
            } catch (IOException e) {
                e.printStackTrace();
            }
            image.flush();
        }
        document.dispose();
    }
}
